<!-- 修改说明：多仓库修改  t  2019-10-31
15-23	支持多仓库：从session中获取仓库id
-->
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>条码操作记录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <jsp:include page="${pageContext.request.contextPath }/resource_path.jsp" flush="true"/>
    <!-- ******************************多仓库修改  t  2019-11-11 开始*************************** -->
    <!-- 从session中获取仓库id -->
    <% Long warehouseId =  (Long)request.getSession().getAttribute("warehouse_id");
        String warehouse_id = "";
        if(warehouseId != null){
            warehouse_id = String.valueOf(warehouseId);
        }
    %>
    <!-- ******************************多仓库修改  t  2019-11-11 结束*************************** -->
</head>
<body class="layui-anim layui-anim-up">
<!-- ******************************多仓库修改  t  2019-11-11 开始*************************** -->
<!-- 利用全局仓库id的input保存session中仓库id -->
<input id="warehouse_id" hidden="hidden" value="<%=warehouse_id%>">
<!-- ******************************多仓库修改  t  2019-11-11 结束*************************** -->
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a>
          <cite>条码操作记录</cite>
        </a>
      </span>
</div>
<div class="x-body">
    <div class="layui-row">
        <div class="layui-form">
            <div class="layui-input-inline">

                <div class="layui-input-inline" >
                    <input class="layui-input" name="startDate" id="startDate" placeholder="请输入开始时间" autocomplete="off" style="display: inline; width: 180px; margin-left: 10px">
                </div>

                <div class="layui-input-inline">
                    &nbsp;-
                </div>

                <div class="layui-input-inline">
                    <input class="layui-input" name="endDate" id="endDate" placeholder="请输入结束时间" autocomplete="off" style="display: inline; width: 180px; margin-left: 10px">
                </div>


                <div class="layui-input-inline">
                    <select style="width: 285px" id="selectType"   lay-filter="selectType">
                        <option value="TYPE_STATE_KK">请选择类型</option>
                        <option value="TYPE_STATE_SH">收货</option>
                        <option value="TYPE_STATE_ZJ">质检</option>
                        <option value="TYPE_STATE_SJ">上架</option>
                        <option value="TYPE_STATE_XJ">下架</option>
                        <option value="TYPE_STATE_CK">出库</option>
                        <option value="TYPE_STATE_CX">拆箱</option>
                        <option value="TYPE_STATE_TZ">调帐</option>
                    </select>
                </div>

                <div class="layui-input-inline">
                    <select style="width: 285px" id="selectState"   lay-filter="selectState">
                        <option value="TYPE_STATE_KK">请选择状态</option>
                        <option value="TYPE_STATE_CG">成功</option>
                        <option value="TYPE_STATE_SB">失败</option>
                    </select>
                </div>

                <div class="layui-input-inline">
                    <input class="layui-input" id="barCode" placeholder="请输入条码/SAP/人员" autocomplete="off" style="display: inline; width: 180px; margin-left: 10px">
                </div>
                <div class="layui-input-inline">
                    <input type="hidden" id="dateTime" onchange="myFunction()">
                </div>

                <div class="layui-input-inline">
                    <button class="layui-btn layui-btn-normal" id="searchId" data-type="reload"><i class="layui-icon layui-icon-search"></i>检索</button>
                    <!-- ******************************优化添加导出  t  2019-11-12 开始*************************** -->
                    <button class="layui-btn layui-btn-danger" data-type="doExcel"><i class="layui-icon layui-icon-upload-drag"></i>导出</button>
                    <!-- ******************************优化添加导出  t  2019-11-12 开始*************************** -->
                </div>
            </div>

        </div>
    </div>
    <table class="layui-hide" id="tableList" lay-filter="tableList"></table>

    <script src="${pageContext.request.contextPath }/js/td/layuiRowspan.js" charset="utf-8"></script>
    <script type="text/javascript" charset="utf-8" language="JavaScript">

        var layer;
        var subtips;
        $(document).ready(function(){
            $('#searchId').mouseover(function () {
                //layer.tips('提示信息', '#searchId',{tips:[1,'#ff6700'],time: 30000})
                //$(".content").show("slow");
                openMsg()
            })
            $('#searchId').mouseout(function () {
                layer.close(subtips);
            })
        });

        function openMsg() {
            //subtips = layer.tips('<div>1.本“操作记录”打开时系统默认不显示列表数据信息；<br/></div>', '#searchId',{tips:[3,'#ff6700'],time: 30000});
            var that = this;
            subtips =layer.tips("<div style='color:#ff6700;'>1.本“操作记录”打开时系统默认不显示列表数据信息；<br/>" +
                "2.请根据查询需要选择或输入筛选条件（筛选条件包括：时间范围、操作类型、操作状态、条码、SAP/QAD、供应商代码、操作人员）；<br/>" +
                "3.点击本按钮，系统按已选定或输入的筛选条件执行检索并显示相应数据信息；<br/>" +
                "4、本按钮左侧的输入框可输入条码或人员的部分信息进行模糊搜索；<br/>" +
                "5、条码信息的前几个字母为供应商代码，通过输入供应商代码，可筛选查询指定供应商的条码操作记录。<br/></div>",'#searchId',{tips:[2,'#fff'],time:0,area: 'auto',maxWidth:500});
        }

        layui.use(['table','layer','upload','form','laydate'], function(){
            var table = layui.table;
            layer = layui.layer;
            var form = layui.form;
            var laydate = layui.laydate;
            var excel = layui.excel;
            //执行一个laydate实例
            laydate.render({
                elem: '#startDate', //指定元素
                type: 'datetime'
            });

            laydate.render({
                elem: '#endDate', //指定元素
                type: 'datetime'
            });
            var $ = layui.jquery, active = {
                reload:function () {
                    var selectType = $("#selectType").val();
                    var selectState = $("#selectState").val();
                    var startDate = $("#startDate").val();
                    var endDate = $("#endDate").val();
                    var barCode = $.trim($("#barCode").val());
                    /* ******************************多仓库修改  t  2019-11-11 开始*************************** */
                    //判断全局仓库id是否为空  不为空加入查询条件
                    var warehouse_id = $.trim($("#warehouse_id").val());
                    /* ******************************多仓库修改  t  2019-11-11 结束*************************** */
                    table.reload('tableList',{
                        method:'post'
                        ,where:{
                            'operatingTime':startDate,
                            'locationId':endDate,
                            'result':selectState,
                            'type':selectType,
                            'barCode':barCode
                            /* ******************************多仓库修改  t  2019-11-11 开始*************************** */
                            //判断全局仓库id是否为空  不为空加入查询条件
                            ,'warehouse_id':warehouse_id
                            /* ******************************多仓库修改  t  2019-11-11 结束*************************** */
                        }
                        ,page: {
                            curr: 1//重新从第 1 页开始
                        }
                    });
                },
                /* ******************************优化添加导出  t  2019-11-12 开始*************************** */
                doExcel:function () {
                    var selectType = $("#selectType").val();
                    var selectState = $("#selectState").val();
                    var startDate = $("#startDate").val();
                    var endDate = $("#endDate").val();
                    var barCode = $.trim($("#barCode").val());
                    var warehouse_id = $.trim($("#warehouse_id").val());
                    $.ajax({
                        url: '${pageContext.request.contextPath }/barCodeOperation/list.do',
                        dataType: 'json',
                        data: {
                            'operatingTime':startDate,
                            'locationId':endDate,
                            'result':selectState,
                            'type':selectType,
                            'barCode':barCode
                            ,'warehouse_id':warehouse_id
                            ,"pageSize":1000000
                            ,"page":1
                        },
                        success: function(res) {
                            var data = res.rows;
                            if(data.length > 0){
                                var exportData = [];
                                data.forEach(function(item){
                                    exportData.push({userName:item.user.userName
                                        ,materiel_num:item.materiel.materiel_num
                                        ,materiel_name:item.materiel.materiel_name
                                        ,operatingTime:item.operatingTime
                                        ,barCode:item.barCode
                                        ,batch:item.batch
                                        ,type:item.type
                                        ,result:item.result})
                                })
                                exportData.unshift({userName:'人员'
                                    ,materiel_num:'SAP/QAD'
                                    ,materiel_name:'中文名称'
                                    ,operatingTime:'操作时间'
                                    ,barCode:'条码'
                                    ,batch:'批次'
                                    ,type:'操作类型'
                                    ,result:'操作结果'});
                                excel.exportExcel({
                                    sheet1: exportData}, '条码操作记录.xlsx', 'xlsx');
                                //table.exportFile(ins1.config.id,exportData, 'xls');
                            }else{
                                toastr.warning("数据为空不能导出！");
                            }
                        },
                        error:function(res){
                            toastr.error("导出失败！");
                        }
                    });
                }
                /* ******************************优化添加导出  t  2019-11-12 结束*************************** */
            }
            $('.layui-btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            /* ******************************优化  t  2019-11-11 开始*************************** */
            //时间段检索默认带入时间：近三个月
            var d = new Date();
            var endDate= d.format("yyyy-MM-dd hh:mm:ss");
            $("#endDate").val(endDate)
            d.setMonth(d.getMonth() - 3);
            var startDate= d.format("yyyy-MM-dd hh:mm:ss");
            $("#startDate").val(startDate)
            /* ******************************优化  t  2019-11-11 结束*************************** */
            //$("#date").val(curentDate())
            var selectType = $("#selectType").val();
            var selectState = $("#selectState").val();
            var startDate = $("#startDate").val();
            var endDate = $("#endDate").val();
            var barCode = $.trim($("#barCode").val());
            /* ******************************多仓库修改  t  2019-11-11 开始*************************** */
            //判断全局仓库id是否为空  不为空加入查询条件
            var warehouse_id = $.trim($("#warehouse_id").val());
            /* ******************************多仓库修改  t  2019-11-11 结束*************************** */
            //var barCode = encodeURIComponent(barCode);
            //console.info("selectType="+selectType);
            //console.info("selectState="+selectState);
            //console.info("startDate="+startDate);
            //console.info("endDate="+endDate);
            //console.info("barCode="+barCode);
            //if ((selectType != 'TYPE_STATE_KK') && (selectState != 'TYPE_STATE_KK') && (startDate == null) && (endDate == null) && (barCode == null)) {
            table.render({
                elem: '#tableList',
                method:'post'
                ,where:{
                    /* ******************************多仓库修改  t  2019-11-12 开始*************************** */
                    //'operatingTime':startDate,
                    //不执行检索或点击时页面默认无信息
                    'operatingTime':"",
                    /* ******************************多仓库修改  t  2019-11-12 结束*************************** */
                    'locationId':endDate,
                    'result':selectState,
                    'type':selectType,
                    'barCode':barCode
                    /* ******************************多仓库修改  t  2019-11-11 开始*************************** */
                    //判断全局仓库id是否为空  不为空加入查询条件
                    ,'warehouse_id':warehouse_id
                    /* ******************************多仓库修改  t  2019-11-11 结束*************************** */
                }
                ,url:'${pageContext.request.contextPath }/barCodeOperation/list.do'
                ,toolbar: '#toolbar'
                ,title: 'machineList'
                ,limits:[10,20,30]
                ,page:true
                //,defaultToolbar:['filter', 'print']
                ,request: {
                    pageName: 'page',
                    limitName: 'pageSize'
                }
                ,response: {
                    countName: 'total',
                    dataName: 'rows'
                }
                ,cols: [[
                    {field:'id',title:'序号',sort: true,width: 60,type:'numbers',align:'center'},
                    {field: 'operator',title: '人员',align:'center', width: 100,
                        templet: function (row){
                            var value = "";
                            if(null != row.user){
                                value = row.user.userName;
                            }
                            return value;
                        },
                    },
                    {field: 'materiel_num',title: '零件号',align:'center', width: 150,
                        templet: function (row){
                            var value = "";
                            if(null != row.materiel){
                                value = row.materiel.materiel_num;
                            }
                            return value;
                        },
                    },
                    /* {field: 'brevity_num',title: '零件号',align:'center', width: 200,
                        templet: function (row){
                            var value = "";
                            if(null != row.materiel){
                                value = row.materiel.brevity_num;
                            }
                            return value;
                        },
                    }, */
                    /* {field: 'materiel_name',title: '中文名称',align:'center',width: 300,
                        templet: function (row){
                            var value = "";
                            if(null != row.materiel){
                                value = row.materiel.materiel_name;
                            }
                            return value;
                        },
                    }, */
                    {field: 'operatingTime',title: '操作时间', width: 200, align:'center'},
                    {field:'barCode', title: '条码', align:'center', width: 600,
                    	templet: function(row){
                    		return '<xmp>'+row.barCode+'</xmp>';
                    	}
                    },
                    {field: 'batch',title: '批次', align:'center'},
                    {field: 'codeNum',title: '数量', align:'center'},
                    {field: 'locationId',title: '库位编号', align:'center'},
                    //{field: 'locationId2',title: '目标库位', align:'center'},
                    {field: 'type',title: '操作类型',  align:'center'},
                    {field: 'result',title: '操作结果', align:'center'},
                    //{field: 'locationId',title: '库区',align:'center'}
                ]]
                ,done : function(){
                    $('th').css({
                        'background-color': '#009688', 'color': '#fff','font-weight':'bold',
                    })
                }
            });
            //}
        });
        //获取当前日期
        function curentDate() {
            var now=new Date();
            var year = now.getFullYear();       //年
            var month = now.getMonth() + 1;     //月
            var day = now.getDate();            //日
            var time=year+"-"+add0(month)+"-"+add0(day);
            return time;
        }
        function add0(m){return m<10?'0'+m:m }
        toastrStyle()
    </script>
</body>
</html>